<?php

namespace app\common\model;

/**
 * Class Knowledge
 * @package app\model
 * @property int $id
 * @property int $userId
 * @property int $checkStatus
 * @property int $categoryId
 * @property int $smallPic
 * @property string $title
 * @property string $content
 * @property int $isHot
 * @property string $keywords
 * @property int $readNum
 * @property int $likeNum
 * @property int $updated
 * @property int $created
 * @property string $smallPicImg
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class Knowledge extends \app\common\model\BaseModel
{
    protected $name = 'Knowledge';

    // 发布人
    public function user()
    {
        return $this->belongsTo(User::class, 'userId', 'id');
    }

    public function category()
    {
        return $this->belongsTo(KnowledgeCategory::class, 'categoryId', 'id');
    }

    public function getSmallPicImgAttr($value, $data)
    {
        return image_url($data['smallPic']);
    }

    public function getSmallPicImgThumbAttr($value, $data)
    {
        return image_url($data['smallPic'], 'thumb');
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'Knowledge表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'Knowledge表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中Knowledge的键');
    //    }
}
